<?php
namespace ShenerCloud\Data\Model;

use ShenerCloud\Exception\DataException;

class Parameter
{
    public $appid="";
    public $appsecret="";
    private $path="";
    public $sn="";
    private $host="https://data.shenercloud.com";
    
    /***
     * 初始化
     * @param string $appid
     * @param string $appsecret
     * @param string $path
     * @param string $host
     */
    public function __construct(string $appid=''
        ,string $appsecret=''
        ,string $path=''
        ,string $host='')
    {
        $appid = trim(stripslashes($appid));
        $appsecret = trim(stripslashes($appsecret));
        $path = trim(stripslashes($path));
        $host = trim(stripslashes($host));
        
        $this->appid = $appid;
        $this->appsecret = $appsecret;
        $this->path = !empty($path)?$path:__DIR__;
        $this->host = !empty($host)?$host:$this->host;
    }
    
    /***
     * 设置用户鉴权SN
     * @param string $sn
     * @return \ShenerCloud\Data\Model\Parameter
     */
    public function setUserSN(string $sn)
    {
        if (!empty($sn))
            $this->sn = trim(stripslashes($sn));
        return $this;
    }
    
    /**
     * 设置应用APPID
     * @param string $appid
     * @return \ShenerCloud\Data\Model\Parameter
     */
    public function setAppid(string $appid)
    {
       $appid = trim(stripslashes($appid));
       if (!empty($appid))
           $this->appid = $appid;
       return $this;
    }
    
    /**
     * 设置应用秘钥
     * @param string $appsecret
     * @return \ShenerCloud\Data\Model\Parameter
     */
    public function setAppsecret(string $appsecret)
    {
        $appsecret = trim(stripslashes($appsecret));
        if (!empty($appsecret))
            $this->appsecret = $appsecret;
        return $this;
    }
    
    /**
     * 设置AccessToken存储路径
     * @param string $path
     * @return \ShenerCloud\Data\Model\Parameter
     */
    public function setPath(string $path)
    {
        $path = trim(stripslashes($path));
        if (!empty($path))
            $this->path = $path;
        return $this;
    }
    
    /***
     * 设置服务端请求路径
     * @param string $host
     * @return \ShenerCloud\Data\Model\Parameter
     */
    public function setHost(string $host)
    {
        $host = trim(stripslashes($host));
        if (!empty($host))
            $this->host = $host;
        return $this;
    }
    
    public function __get($name)
    {
        if (isset($this->{$name}))
            return $this->{$name};
        throw new DataException("The {$name} are't undefined");
    }
}